<template>
	<view>
		<u-tabs-swiper ref="tabs" :list="tabList" :is-scroll="false" bar-width="100" gutter="100"
		active-color="#e93323" @change="tabsChange" :current="tabsCurrent"
		></u-tabs-swiper>
		<view class="page-bg-gray"></view>
		<view class="u-wrap">
			<view class="jingdong" :class="tabsCurrent > 0 ? 'disable':''" v-for="(item,index) in couponList" :key="index">
				<view class="left">
					<view class="sum" v-if="item.coupon_type === 1 || item.coupon_type === 3">
						￥<text class="num">{{ item.discount_money / 100 }}</text>
					</view>
					<view class="sum" v-if="item.coupon_type === 2 || item.coupon_type === 4">
						<text class="num">{{ item.discount_ratio / 1000 }}</text> 折
					</view>
					<view class="type" v-if="item.is_threshold === 0">无门槛</view>
					<template v-else>
					<view class="type" v-if="item.coupon_type === 1 || item.coupon_type === 2">满{{ item.threshold_money / 100 }}元可用</view>
					<view class="type" v-if="item.coupon_type === 3 || item.coupon_type === 4">满{{ item.threshold_num }}件可用</view>
					</template>
				</view>
				<view class="right">
					<view class="top">
						<view class="title">
							<text class="tag" v-if="item.use_goods_type === 0">全品类</text>
							<text class="tag" v-if="item.use_goods_type === 1 || item.use_goods_type === 2">限品类</text>
							<text class="tag" v-if="item.use_goods_type === 3 || item.use_goods_type === 4">限商品</text>
							<text>{{ item.title }}</text>
						</view>
						<view class="bottom">
							<view class="date u-line-1">
								<template v-if="item.receive_time_type === 1">
									{{$u.timeFormat(item.receive_time_start, 'yyyy.mm.dd')}}-{{$u.timeFormat(item.receive_time_end, 'yyyy.mm.dd')}}
								</template>
							</view>
							<view class="immediate-use" v-if="tabsCurrent === 0" @click="gotoHome">去使用</view>
						</view>
					</view>
					<view class="tips">
						<view class="explain">
							<u-icon name="zhuanfa" class="transpond" :size="24"></u-icon>
							<text>可赠送</text>
						</view>
						<view class="explain" @click="openDetails(item.id)">
							<u-icon name="info-circle" class="transpond" :size="24"></u-icon>
							<text>详情</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="addSite" @tap="toMoreCoupon">
			<view class="add">
				领取更多优惠券
			</view>
		</view>
		<u-popup mode="bottom" safe-area-inset-bottom v-model="detailsShow">
			<view class="detailsContent">
				<scroll-view scroll-y="true" style="height: 600rpx;">
					<view>
						<mp-html :content="couponContent" :lazy-load="true">
							<u-loadmore v-if="couponContentIsLoading" :status="'loading'" />
						</mp-html>
					</view>
				</scroll-view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import mpHtml from '@/plugins/mp-html/mp-html.vue'
export default {
	components: {
		mpHtml
	},
	data() {
		return {
			tabList: [
				{
					name:'未使用'
				},
				{
					name:'已使用'
				},
				{
					name:'已过期'
				},
			],
			detailsShow: false,
			tabsCurrent:0,
			couponContent: '',
			couponContentIsLoading: true,
			couponList: []
		}
	},
	onLoad() {
		this.getListData()
	},
	methods:{
		tabsChange(_index){
			this.tabsCurrent = _index
			this.couponList = []
			this.getListData()
		},
		getListData(){
			const that = this
			uni.showLoading({
				
			})
			that.$api.coupon.my({type:this.tabsCurrent+1}).then(res => {
				that.couponList = res
				uni.hideLoading()
			}).catch(err => {
				uni.hideLoading()
				console.log(err)
			})
		},
		toMoreCoupon(){
			this.$myRouter.push({
				name: 'coupon/index'
			})
		},
		openDetails(_id){
			this.detailsShow = true;
			const that = this
			that.couponContentIsLoading = true
			that.$api.coupon.details({coupon_id:_id}).then(res => {
				that.couponContentIsLoading = false
				console.log(res)
				if (res){
					that.couponContent = res
				} else{
					that.couponContent = '优惠券详情未填写'
				}
			}).catch((err) => {
				that.$u.toast('失败，' + err.message)
			})
		},
		gotoHome(){
			this.$myRouter.pushTab({name:'index/index',params:{}})
		},
	}
}
</script>

<style lang="scss" scoped>
.u-wrap {
	padding:0 24rpx 60rpx 24rpx;
}

.jingdong {
	margin-top: 20rpx;
	width: 700rpx;
	height: auto;
	background-color: #ffffff;
	display: flex;
	.left {
		width: 400rpx;
		background-color: rgb(95, 148, 224); //rgb(94, 152, 225);
		text-align: center;
		font-size: 28rpx;
		color: #ffffff;
		.sum {
			margin-top: 50rpx;
			font-weight: bold;
			font-size: 32rpx;
			.num {
				font-size: 60rpx;
			}
		}
		.type {
			margin-bottom: 50rpx;
			font-size: 24rpx;
		}
	}
	.right {
		padding: 20rpx 20rpx 0;
		font-size: 28rpx;
		width: 100%;
		.top {
			border-bottom: 2rpx dashed $u-border-color;
			.title {
				height: 100rpx;
				line-height: 40rpx;
				.tag {
					padding: 4rpx 20rpx;
					background-color: rgb(73, 154, 201);
					border-radius: 20rpx;
					color: #ffffff;
					font-weight: bold;
					font-size: 24rpx;
					margin-right: 10rpx;
				}
			}
			.bottom {
				display: flex;
				margin-top: 20rpx;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 10rpx;
				.date {
					font-size: 20rpx;
					flex: 1;
					margin-right: 20rpx;
				}
				.immediate-use {
					height: auto;
					padding: 0 20rpx;
					font-size: 24rpx;
					border-radius: 40rpx;
					line-height: 40rpx;
					color: rgb(117, 142, 165);
					border: 2rpx solid rgb(117, 142, 165);
				}
			}
		}
		.tips {
			width: 100%;
			line-height: 50rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 24rpx;
			.transpond {
				margin-right: 10rpx;
			}
			.explain {
				display: flex;
				align-items: center;
			}
			.particulars {
				width: 30rpx;
				height: 30rpx;
				box-sizing: border-box;
				padding-top: 8rpx;
				border-radius: 50%;
				background-color: $u-type-info-disabled;
				text-align: center;
			}
		}
	}
	&.disable{
		.left{
			background-color: #CCC;
		}
		.right{
			.top{
				.title{
					.tag{
						background-color: #CCC;
					}
				}
			}
		}
	}
}
.detailsContent{
	padding: 30rpx;
}
.addSite {
	display: flex;
	justify-content: space-around;
	width: 600rpx;
	line-height: 100rpx;
	position: absolute;
	bottom: 30rpx;
	left: 80rpx;
	background-color: red;
	border-radius: 60rpx;
	font-size: 30rpx;
	.add{
		display: flex;
		align-items: center;
		color: #ffffff;
		.icon{
			margin-right: 10rpx;
		}
	}
}
</style>
